#ifndef TERRAIN_H
#define TERRAIN_H

#include "d3dUtil.h"
#include "GlobalMessage.h"
#include "VertexFormat.h"
#include "TerrainInformation.h"

class Terrain
{
public:
	Terrain(void);
	~Terrain(void);

	void Init(ID3D10Device* device,const TerrainInformation& info);

	void SetTerrainInformation(const TerrainInformation& info);

	void SetDirectionToSun(const D3DXVECTOR4& vDirection);

	//set the vertex and index buffer
	void SetBuffer();

	void LoadHeightMap();

	void Smooth();

	//get xx method
	float GetHeight(float x,float y);

	UINT GetNumFaces();

	ID3D10Buffer* GetVertexBuffer();

	ID3D10Buffer* GetIndexBuffer();

	TerrainInformation* GetTerrainInfomation();

	void Destory();

private:
	inline bool IsBound(UINT x,UINT y);
	float Average(UINT x,UINT y);

	void BuildVB();
	void BuildIB();

private:
	//vertex buffer and index buffer
	ID3D10Device*				m_pDevice;
	ID3D10Buffer*				m_pVB;
	ID3D10Buffer*				m_pIB;

	TerrainInformation			m_terrainInfo;

	UINT						m_uiNumVertex;
	UINT						m_uiNumFace;

	std::vector<float>			m_vecHeightmap;
};

#endif